//
//  NSObject+SJShare.m
//  WSL
//
//  Created by CJ on 2018/1/28.
//  Copyright © 2018年 sanjuetech. All rights reserved.
//

#import "NSObject+SJShare.h"

@implementation NSObject (SJShare)


/**
 分享
 @param imageArray 图片数组
 @param content 分享内容
 @param title 分享标题
 @param url 跳转url
 */
- (void)share:(SSDKPlatformType)platformType imageArray:(NSArray *)imageArray content:(NSString *)content title:(NSString *)title url:(NSString *)url {
    
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:content
                                     images:imageArray
                                        url:[NSURL URLWithString:url]
                                      title:title
                                       type:SSDKContentTypeAuto];
    //优先使用平台客户端分享
    [shareParams SSDKEnableUseClientShare];
    
    [ShareSDK share:platformType parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
        
        switch (state) {
                
            case SSDKResponseStateBegin:
                
                break;
            case SSDKResponseStateSuccess:
                
                [SVProgressHUD showSuccessWithStatus:@"分享成功"];
                // 延迟2秒后消失
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
                
                break;
            case SSDKResponseStateFail:
                [SVProgressHUD showErrorWithStatus:@"分享失败"];
                // 延迟2秒后消失
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
                break;
            case SSDKResponseStateCancel:
                
                break;
            case SSDKResponseStateBeginUPLoad:
                
                break;
        }
        
    }];
    
}

@end
